ROOTDIR = .
EXE_DIR = ./out
LPATH = -L.


# CC=gcc
# CFLAGS=-Wall -Werror -Wextra -Os -fPIE
# LD=ld
# LDFLAGS=-melf_x86_64 -r --whole-archive
RM = -rm -rf
CC="zig cc -target x86_64-linux-gnu"
CXX="zig c++ -target x86_64-linux-gnu"
AR="zig ar" 
RANLIB="zig ranlib"
USE_JEMALLOC=no
USE_SYSTEMD=no


# zig build --help
ZIG = zig build run
ZIGFLAGS = -Dtarget=x86_64-linux-gnu -Drelease-safe --cache-dir ./out/zig-cache
# -Drelease-small --strip
# -Drelease-fast
# --single-threaded
# -march=native
# "x86_64-linux-gnu",
# "x86_64-linux-gnux32",
# "x86_64-linux-musl",
# x86_64-windows x86_64-macosx aarch64v8-linux
exclude_dirs:=out src 
dirs:=$(shell find . -maxdepth 1 -type d)
dirs:=$(basename $(patsubst ./%,%,$(dirs)))
dirs:=$(filter-out $(exclude_dirs),$(dirs))
SUBDIRS := $(dirs)


.PHONY: clean picoz

all: picoz

# %.o: %.c
#     $(CC) -o $@ -c $(CFLAGS) $^

# echo_test_with_address:
#     @echo "hello world"

picoz:
	@mkdir -p $(EXE_DIR)$  
	$(ZIG) -p $(EXE_DIR) $(ZIGFLAGS)

# cimport:
# 	zig build-exe $(ZIGFLAGS) cimport.zig -lc -lraylib
# curltest:
# 	zig build-exe zig-curl-test.zig --library curl --library c $(pkg-config --cflags libcurl)

subdirs:$(SUBDIRS)
	for r in $(SUBDIRS); do \
	$(MAKE) -C $$r all||exit 1;\
	done

clean:
	$(RM) *.o *.a ./out/bin